package com.ruoyi.web.controller.business.statistics.factory;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.business.sundry.domain.JbProductRecipe;
import com.ruoyi.business.sundry.service.JbProductRecipeService;
import com.ruoyi.web.core.JoController;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * 业务 配方 工厂
 *
 * @author Jyl
 */
@Log4j2
@Component
public class JbProductRecipeFactory extends JoController
{
    @Autowired
    private JbProductRecipeService jbProductRecipeService;

    /**
     * @param commodityIds 商品主键集合
     * @return 配方集合
     */
    public List<JbProductRecipe> list(List<Long> commodityIds)
    {
        return jbProductRecipeService.list(new LambdaQueryWrapper<JbProductRecipe>()
                .in(JbProductRecipe::getCommodityId, commodityIds)
                .orderByDesc(JbProductRecipe::getCreateTime));
    }

    /**
     * 是否有全部商品
     */
    public Boolean isGoodsAll()
    {
        return jbProductRecipeService.synchronizationGoods();
    }

    /**
     * @param commodityId       商品id
     * @param inventoryCost     库存成本
     * @param inventoryUnitCost 库存成本-核算单价
     * @return 执行结果
     */
    public Boolean updateByCommodityCode(Long commodityId, BigDecimal inventoryCost, BigDecimal inventoryUnitCost)
    {
        return jbProductRecipeService.update(new LambdaUpdateWrapper<JbProductRecipe>()
                .eq(JbProductRecipe::getCommodityId, commodityId)
                .set(JbProductRecipe::getInventoryUnitCost, inventoryUnitCost)
                .set(JbProductRecipe::getInventoryCost, inventoryCost)
        );
    }
}
